<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include/header::html('登录')" ></head>

<body >

<script>

    $(function(){
        var loginVue={
            user:{id:'',password:''},
        };
        var vue=new Vue({
            el: '#loginDiv',
            data: loginVue,
            mounted: function () {

            },
            methods: {
                loginCheck:function () {
                    var url = "/users/login";
                    axios.post(url,vue.user).then(function (response) {
                        var result = response.data;
                        if(result.code==0){
                            var storage=window.localStorage;
                            console.log(window.localStorage);
                            storage.setItem("fan_access_token",result.access_token);
                            storage.setItem("fan_userId",result.userId);
                            storage.setItem("fan_userName",result.username);

                            document.cookie = "token="+result.access_token+";path=/;";
                            console.log(result.access_token);

                            location.href="/view/follow/index";
                        }else{
                            alert(result.msg);
                        }
                    });
                },
            },
        });
    });

</script>
<style>
    table{
        margin:20px;
    }
</style>

<div id="loginDiv">
    <table class="table table-bordered table-condensed">
        <thead>
        <th align="center" colspan="4">模拟投资系统</th>
        </thead>
        <tbody>
        <div class="loginErrorMessageDiv" style="visibility: hidden">
            <div class="alert alert-danger" >
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                <span class="errorMessage"></span>
            </div>
        </div>
        <tr>
            <td align="right">账号:</td>
            <td><input type="text" class="form-control" v-model="user.id"></td>
        </tr>
        <tr>
            <td align="right">密码:</td>
            <td><input type="password" class="form-control" v-model="user.password"></td>
        </tr>
        </tbody>
    </table>
    <div class="modal-footer" style="text-align:center;">
        <button class="btn btn-primary" @click="loginCheck" type="button">登录</button>
    </div>
</div>

<div th:replace="include/footer::html" ></div>
</body>
</html>